package com.chinacache.maint.webssh.action.ssh;

import org.springframework.beans.factory.annotation.Required;

import com.chinacache.maint.commons.orm.hibernate.Page;
import com.chinacache.maint.commons.web.struts2.CRUDActionSupport;
import com.chinacache.maint.webssh.entity.ssh.Device;
import com.chinacache.maint.webssh.service.ssh.DeviceManager;

@SuppressWarnings("serial")
public class DeviceAction extends CRUDActionSupport<Device> {
	private DeviceManager manager;
	private Device entity;
	private String id;
	private Page<Device> page = new Page<Device>();
	private String condition;

	// public void setManager(DeviceManager manager) {
	// this.manager = manager;
	// }

	public String getCondition() {
		return condition;
	}

	public void setCondition(String condition) {
		this.condition = condition;
	}

	@Required
	public void setDeviceManager(DeviceManager deviceManager) {
		manager = deviceManager;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Override
	public String delete() throws Exception {
		return null;
	}

	@Override
	public Device getModel() {
		return entity;
	}

	@Override
	public Page<Device> getPage() {
		return page;
	}

	@Override
	public String list() throws Exception {
		page = manager.getAllDeviceByCondition(page, condition);
		return SUCCESS;
	}

	@Override
	public void prepare() throws Exception {
		if (id != null) {
			entity = manager.getDevice(id);
		} else {
			entity = new Device();
		}
	}

	@Override
	public String save() throws Exception {
		return null;
	}

}
